From 4148795c8bb4ea391ef690957fd2396b7635acb3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 8 Nov 2017 20:53:49 -0500 Subject: [PATCH] filesystem: Add GIcon getters We want to move away from surfaces, and instead pass GIcons and GdkTextures around. --- gtk/gtkfilesystem.c | 52 +++++++++++++++++++++++++++++++++++++++------ gtk/gtkfilesystem.h | 4 ++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c index f6edb4e2b9..8a2fc3b0af 100644 --- a/gtk/gtkfilesystem.c +++ b/gtk/gtkfilesystem.c @@ -745,14 +745,10 @@ get_surface_from_gicon (GIcon *icon, return surface; } -cairo_surface_t * -_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, - GtkWidget *widget, - gint icon_size, - GError **error) +GIcon * +_gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume) { GIcon *icon = NULL; - cairo_surface_t *surface; if (IS_ROOT_VOLUME (volume)) icon = g_themed_icon_new ("drive-harddisk"); @@ -763,6 +759,20 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, else if (G_IS_MOUNT (volume)) icon = g_mount_get_icon (G_MOUNT (volume)); + return icon; +} + +cairo_surface_t * +_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, + GtkWidget *widget, + gint icon_size, + GError **error) +{ + GIcon *icon = NULL; + cairo_surface_t *surface; + + icon = _gtk_file_system_volume_get_icon (volume); + if (!icon) return NULL; @@ -870,6 +880,36 @@ _gtk_file_info_render_icon_internal (GFileInfo *info, return surface; } +GIcon * +_gtk_file_info_get_icon (GFileInfo *info, + int icon_size, + int scale) +{ + GIcon *icon; + GdkPixbuf *pixbuf; + const gchar *thumbnail_path; + + thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); + + if (thumbnail_path) + { + pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path, + icon_size*scale, icon_size*scale, + NULL); + + if (pixbuf != NULL) + return G_ICON (pixbuf); + } + + icon = g_file_info_get_icon (info); + if (icon) + return g_object_ref (icon); + + /* Use general fallback for all files without icon */ + icon = g_themed_icon_new ("text-x-generic"); + return icon; +} + cairo_surface_t * _gtk_file_info_render_icon (GFileInfo *info, GtkWidget *widget, diff --git a/gtk/gtkfilesystem.h b/gtk/gtkfilesystem.h index a2b144cd93..0a3db1aae6 100644 --- a/gtk/gtkfilesystem.h +++ b/gtk/gtkfilesystem.h @@ -94,6 +94,7 @@ gchar * _gtk_file_system_volume_get_display_name (GtkFileSystemVol gboolean _gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume); GFile * _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume); GIcon * _gtk_file_system_volume_get_symbolic_icon (GtkFileSystemVolume *volume); +GIcon * _gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume); cairo_surface_t * _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume, GtkWidget *widget, gint icon_size, @@ -106,6 +107,9 @@ void _gtk_file_system_volume_unref (GtkFileSystemVol cairo_surface_t * _gtk_file_info_render_icon (GFileInfo *info, GtkWidget *widget, gint icon_size); +GIcon * _gtk_file_info_get_icon (GFileInfo *info, + int icon_size, + int scale); gboolean _gtk_file_info_consider_as_directory (GFileInfo *info); -- 2.30.2